package com.info33.platform.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.info33.platform.common.mvc.controller.BaseController;
import com.info33.platform.common.mvc.vo.Result;
import com.info33.platform.common.validated.SaveValidated;
import com.info33.platform.common.validated.ValidList;
import com.info33.platform.system.entity.SysShortcutMenu;
import com.info33.platform.system.service.SysShortcutMenuService;
import com.info33.platform.system.vo.SysShortcutMenuListVO;
import com.info33.platform.system.vo.SysShortcutMenuVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author admin
 */
@RestController
@RequestMapping("/SysShortcutMenu")
@Api(tags = "系统 - 快捷菜单")
public class SysShortcutMenuController extends BaseController<SysShortcutMenuService, SysShortcutMenu> {

    private final SysShortcutMenuService sysShortcutMenuService;

    @Autowired
    public SysShortcutMenuController(SysShortcutMenuService sysShortcutMenuService) {
        super(sysShortcutMenuService);
        this.sysShortcutMenuService = sysShortcutMenuService;
    }
    
    @GetMapping(value = "/listShortcutMenu")
    @ApiOperation(value = "分页获取快捷菜单列表")
    public Result<List<SysShortcutMenuListVO>> listShortcutMenu() {
        return Result.ok(sysShortcutMenuService.listShortcutMenu(getCurrentUser()));
    }
    
    @GetMapping(value = "/pageShortcutMenu/{pageNum}/{pageSize}")
    @ApiOperation(value = "分页获取快捷菜单列表")
    public Result<Page<SysShortcutMenuVO>> pageShortcutMenu(@PathVariable int pageNum, @PathVariable int pageSize) {
        return Result.ok(sysShortcutMenuService.pageShortcutMenu(new Page<>(pageNum, pageSize), getCurrentUser()));
    }
    
    @PostMapping("/saveBatch")
    @ApiOperation(value = "批量增加")
    public Result<List<SysShortcutMenu>> saveBatchShortcutMenu(
            @Validated(value = {SaveValidated.class}) @RequestBody ValidList<SysShortcutMenu> sysShortcutMenuList) {
        return sysShortcutMenuService.saveBatchShortcutMenu(sysShortcutMenuList, getCurrentUser());
    }
    
    @PostMapping("/removeBatch")
    @ApiOperation(value = "批量删除")
    public Result<?> removeBatch(@RequestBody List<Long> idList) {
        return sysShortcutMenuService.removeByIds(idList) ? Result.ok() : Result.error();
    }
    
}